package com.tdkj.action.backstage.shop;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.tdkj.action.BaseAction;
import com.tdkj.model.shop.BeanOrder;
import com.tdkj.service.shop.IBeanOrderService;
import com.tdkj.util.typeconverter.DateTypeConverter;


public class OrderManageAction extends BaseAction {
    
	private IBeanOrderService orderService;
	
	private Long id;
	
	private List<BeanOrder> orders ;
	
	
	public String execute() {
		
		
		String keyword = this.getQueryInfo().get("keyword");
		String column = this.getQueryInfo().get("column");
		Date createTimeStart = DateTypeConverter.convertToDate(this.getQueryInfo().get("createTimeStart")==null?"":this.getQueryInfo().get("createTimeStart"));
		Date createTimeEnd = DateTypeConverter.convertToDate(this.getQueryInfo().get("createTimeEnd")==null?"":this.getQueryInfo().get("createTimeEnd"));

		
		String hql = "from " + BeanOrder.class.getName() + " as bean where 1=1";
		
		if(keyword!=null && column!=null && !"".equals(keyword) && !"".equals(column)){
			hql = hql + " and bean."+column+" like '%"+keyword+"%' ";
		}
		if(createTimeStart!=null){
			hql = hql + " and bean.createTime>='"+DateTypeConverter.convertToString(createTimeStart,"yyyy-MM-dd")+"' ";
		}
		if(createTimeEnd!=null){
			hql = hql + " and bean.createTime<='"+DateTypeConverter.convertToString(createTimeEnd,"yyyy-MM-dd")+"' ";
		}
		hql = hql + " order by bean.createTime desc";
		
		Query query = this.createQuery(hql);
		
		this.queryByPage(query, "orderManageAction.action", 10);
		return "success";
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<BeanOrder> getOrders() {
		return orders;
	}

	public void setOrders(List<BeanOrder> orders) {
		this.orders = orders;
	}

	@Resource
	public void setOrderService(IBeanOrderService orderService) {
		this.orderService = orderService;
	}

}
